How to solve these coding challenges:
Write your solution in PyCharm or in your preferred Python IDE.
If your solution is not correct, then try to understand the error messages, watch the video again, rewrite the solution, and test it again. Repeat this step until you get the correct solution.
Save the solution in a file for future reference or recap.
Challenge #1
Write a Python function that takes a list as an argument and returns a new list with unique elements of the first list in the same order.
Sample List : [1,2,3,3,3,3,4,5, 1, 3, 5, 5, 5]
Unique List : [1, 2, 3, 4, 5]
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #2
Write a Python function to check whether a number is perfect or not. The function should return True if the number is perfect and False otherwise.
Perfect numbers: https://www.britannica.com/science/perfect-number
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #3
Write a function that returns the factorial of a number n which is the function's argument.
Factorial: https://en.wikipedia.org/wiki/Factorial
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #4
Create a function that takes an integer as an argument and returns True if its a prime number and False otherwise.
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #5
Using the function defined in the previous challenge find 5 prime numbers greater than 1,000,000
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #6
Write a function called fibo that takes an integer greater than 10 as an argument and returns the Fibonacci series between 0 and the function's argument.
Fibonacci Series: https://www.mathsisfun.com/numbers/fibonacci-sequence.html
Example: fibo(23) will return 0, 1, 1, 2, 3, 5, 8, 13, 21
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #7
Write a function that takes a list as an argument and returns the Equilibrium Index of the list. If there isn't such an index it returns False.
Equilibrium index: https://www.geeksforgeeks.org/equilibrium-index-of-an-array/
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #8
Change the solution of the previous challenge so that the function receives a string of numbers separated by a comma.
Example:
nums = '2, 3, 10, 5'
print(equilibrium_index(nums)) # => 2
nums = '3, 3, 10, 5'
print(equilibrium_index(nums)) # => False
Are you stuck? Do you want to see the solution for this exercise? Click here.
Challenge #9
Define a function that draws a Christmas tree using asterisks (*). The function takes a single argument, which is the height of the tree.
Example: by calling draw_tree(5) it will display:
*
***
*****
*******
*********
Are you stuck? Do you want to see the solution for this exercise? Click here.